

# include "banner.h"

# include <stdio.h>
# include <malloc.h>
# include <string.h>

# include "word_banner.h"
# include "string_banner.h"

typedef int zint_32;
typedef char zchar_8;

pWord InitWord(zchar_8* Sting, zint_32 Size)
{
	if (Sting == NULL || Size == 0)
		return NULL;
	
	pWord pWordTest;
	pWordTest = (pWord)malloc(sizeof(Word));
	pWordTest->Size = Size;
	pWordTest->FirstLetter = *Sting;
	pWordTest->Addres = Sting;

	memcpy(pWordTest->Addres, Sting, Size);
	return pWordTest;
}

State_banner ShowWord(pWord pWordTest)
{
	if (pWordTest == NULL)
		return -1;
		
	printf("Word: %s \t %c \t %d \n", pWordTest->Addres, pWordTest->FirstLetter, pWordTest->Size);
	return 0;
}

zint_32 CompareWord(pWord pFirstWord, pWord pSoundWord)
{	
	zint_32 result = 0;
	if (pFirstWord->Size > pSoundWord->Size)
	{
		result = StringCompare(pFirstWord->Addres, pSoundWord->Addres, pSoundWord->Size);
		if (result == 0)
			result = 1;
	}
	else if (pFirstWord->Size < pSoundWord->Size)
	{
		result = StringCompare(pFirstWord->Addres, pSoundWord->Addres, pFirstWord->Size);
		if (result == 0)
			result = -1;
	}
	else
		result = StringCompare(pFirstWord->Addres, pSoundWord->Addres, pFirstWord->Size);
	
	return result;

}


zint_32 DeleteWord(Word **pWordTest)
{
	if (*pWordTest != NULL)
	{
		DeleteString(&((*pWordTest)->Addres));
		free(*pWordTest);
		*pWordTest = NULL;
	}
	
	return 0;
}


